import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
import java.util.Set;

import org.htmlcleaner.CleanerProperties;
import org.htmlcleaner.HtmlCleaner;
import org.htmlcleaner.PrettyXmlSerializer;
import org.htmlcleaner.TagNode;

public class  ClassDataPage {
	private TagNode tagNode;
	public  ClassDataPage(String url) throws MalformedURLException, IOException{
		CleanerProperties props = new CleanerProperties();
		 
		// set some properties to non-default values
		props.setTranslateSpecialEntities(true);
		props.setTransResCharsToNCR(true);
		props.setOmitComments(true);
		
		
		
		tagNode = new HtmlCleaner(props).clean(
			    new URL(url)
		);
		

		new PrettyXmlSerializer(props).writeToFile(
			    tagNode, "testBanana.xml", "utf-8"
			);
	}
	
	public ClassModel gatherInitialInformation() throws MalformedURLException, IOException{
	
		return null;
	}
	public static TagNode findTagNodeForName(TagNode node,String name,String attribute_name, String attribute_value){
		if(node.getName() != null && node.getName().equals(name)){
		//	System.out.println("Looking into attributes for :" + node.getName());
			Map<String,String> attributes = node.getAttributes();
			Set<String> keySet = attributes.keySet();
		
			for(String key: keySet){
				if(key.equals(attribute_name) && attributes.get(key).equals(attribute_value)){
					return node;
				}
			}
		}
	
		TagNode[] tags = node.getChildTags();
		for(TagNode tag:tags){
			TagNode newTag = findTagNodeForName(tag,name,attribute_name, attribute_value);
			if(newTag != null){
				return newTag;
			}
		}
	return null;

}
public static TagNode getChildByNumber(TagNode parent,int number){
	TagNode[] childTags = parent.getChildTags();
	return childTags[number];

}
}
